using System.IO;
using System.Text;

namespace GameFrameWork.Editor
{
    public partial class PlatformPackage
    {

        private static string BuildInfoFile = "Assets/Game/Repository/Configs/BuildInfo.txt";

        private static void SetDomainName(string domainName)
        {
            string[] buildInfoTxt = File.ReadAllLines(BuildInfoFile, Encoding.UTF8);
            for (int i = 0; i < buildInfoTxt.Length; i++)
            {
                string txt = buildInfoTxt[i];
                if (txt.Contains("DomainName"))
                    buildInfoTxt[i] = string.Format("	\"DomainName\": \"{0}\",", domainName);
            }
            File.WriteAllLines(BuildInfoFile, buildInfoTxt);
            var url = domainName;
            if (!url.EndsWith('/'))
                url += '/';
            SetCheckVersionUrl($"{url}versionMd5");
        }

        private static void SetCheckVersionUrl(string url)
        {
            string[] buildInfoTxt = File.ReadAllLines(BuildInfoFile, Encoding.UTF8);
            for (int i = 0; i < buildInfoTxt.Length; i++)
            {
                string txt = buildInfoTxt[i];
                if (txt.Contains("CheckVersionUrl"))
                    buildInfoTxt[i] = string.Format("	\"CheckVersionUrl\": \"{0}\",", url);
            }
            File.WriteAllLines(BuildInfoFile, buildInfoTxt);
        }
    }
}

